﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using Dsl.Ped.AddIn.Java.Projections.MethodProjection;
using Dsl.Ped.Framework.Common;
using Dsl.Ped.Framework.Projections;

namespace Dsl.Ped.AddIn.Java.Generated
{
    /// <summary>
    /// This is the abstract class that enhances the <see cref="Method"/> class 
    /// provided in the model of projections, these are organized into containers
    /// </summary>
    public partial class Method : IProjective, IDataErrorInfo
    {
        public override List<IProjectionContainer> GetProjectionContainers()
        {
            var projections = new List<IProjectionContainer>();

            projections.Add(
                new ProjectionContainer("Default").RegisterProjection(
                    "Default", MethodProjectionFactory.GetProjection(this, () => name, () => parameters, () => this.parameters.Add(new Parameter() { name = "parameter", type = "int" }))));
            projections.Add(new ProjectionContainer("Just Name")
                .RegisterProjection("JustName", ValueProjectionFactory.GetTextBoxProjection(this, () => name)));
            return projections;
        }

        #region IDataErrorInfo Members

        public string Error
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        public string this[string propertyName]
        {
            get
            {
                string validationResult;
                switch (propertyName)
                {
                    case "name":
                        validationResult = validateName();
                        break;
                    default:
                        throw new ApplicationException("Unknown Property being validated.");
                }
                return validationResult;
            }
        }

        private string validateName()
        {
            return (String.IsNullOrEmpty(this.name) || this.name.Contains(" ")) ? "Class name must be specified" : String.Empty;
        }

        #endregion
    }
}
